/*
 
(c) 2008 by Sławek Kruczek
slav.mir@gmail.com
 

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/


package analytics;

import analytics.util.*;
import java.util.HashMap;
import java.util.Map;


public class UnaryFunctions {
    private static Map<String, UnaryFunction> builtin = new HashMap<String, UnaryFunction>();
    
    static {
        builtin.put("sin", new UnaryFunction() {
            public double eval(double x) {
                return Math.sin(x);
            }
        });
        
        builtin.put("asin", new UnaryFunction() {
            public double eval(double x) {
                return Math.asin(x);
            }
        });
        
        builtin.put("cos", new UnaryFunction() {
            public double eval(double x) {
                return Math.cos(x);
            }
        });
        
        builtin.put("acos", new UnaryFunction() {
            public double eval(double x) {
                return Math.acos(x);
            }
        });
        
        builtin.put("tan", new UnaryFunction() {
            public double eval(double x) {
                return Math.tan(x);
            }
        });
        
        builtin.put("atan", new UnaryFunction() {
            public double eval(double x) {
                return Math.atan(x);
            }
        });
        
        builtin.put("log", new UnaryFunction() {
            public double eval(double x) {
                return Math.log(x);
            }
        });
        
        builtin.put("log10", new UnaryFunction() {
            public double eval(double x) {
                return Math.log10(x);
            }
        });
        
        builtin.put("neg", new UnaryFunction() {
            public double eval(double x) {
                return -x;
            }
        });
    }
    
    
    private Map<String, UnaryFunction> custom = new HashMap<String, UnaryFunction>();
    
    public void add(String name, UnaryFunction fun) {
        custom.put(name, fun);
    }
    
    public UnaryFunction get(String name) {
        UnaryFunction result = custom.get(name);
        
        if(result == null) return builtin.get(name);
        else return result;
    }
    
    public UnaryFunction remove(String name) {
        return custom.remove(name);
    }

}
